package com.zmn.brs.dubbo.impl.blacklist;

import com.zmn.brs.business.interfaces.blacklist.BlacklistBService;
import com.zmn.brs.common.exception.BrsException;
import com.zmn.brs.common.model.dio.blacklist.BlacklistDIO;
import com.zmn.brs.dubbo.constant.DubboConsts;
import com.zmn.brs.dubbo.interfaces.blacklist.BlacklistListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * 描述: 黑名单远程接口实现
 *
 * @author wangjie
 * @since 2019/8/2
 **/
@Slf4j
@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class BlacklistListRemoteServiceImpl implements BlacklistListRemoteService {

    @Resource
    private BlacklistBService blacklistBService;

    /**
     * 描述: 黑名单限制规则
     *
     * @param blacklistDio
     *            黑白名单检查入参对象
     * @return com.zmn.common.dto.ResponseDTO<java.lang.Boolean>
     * @author wangjie
     * @since 2019/8/2
     **/
    @Override
    @ReadOnlyConnection
    public ResponseDTO<Boolean> checkBlacklistConstraintRules(BlacklistDIO blacklistDio) {
        log.info("checkBlacklistConstraintRules参数blacklistDio：{}", blacklistDio);
        try {
            Boolean result = blacklistBService.checkBlacklistConstraintRules(blacklistDio);
            if (!result) {
                return ResponseDTO.fail();
            }
            return ResponseDTO.success();
        } catch (BrsException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.info("黑白名单检查程序异常", e);
            return ResponseDTO.fail();
        }
    }
}
